package day20240918;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/RequestServlet0")
public class RequestServlet0 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter writer = resp.getWriter();

       /* // 输出：你好，null
        writer.write("你好,null");
        writer.write('\n');*/

        /*// 输出：你好，傻逼
        String name = req.getParameter("name");
        writer.write(name);
        writer.write('\n');*/

      /*  //直接打印 request 和 response 是由谁实现的
        writer.write(req + " ===== " + resp);
        writer.write('\n');*/

       /* // 输出：getMethod、getContextPath、getRequestURL、getRequestURI、getQueryString、getHeader("user-agent")
        // System.lineSeparator()
        String method = req.getMethod();
        String contextPath = req.getContextPath();
        String requestURI = req.getRequestURI();
        String queryString = req.getQueryString();
        String header = req.getHeader("user-agent");
        writer.write("method: " + method + "\n" + "contextPath: " + contextPath + "\n" + "requestURI: " + requestURI + "\n" + "queryString: " + queryString + "\n" + "header: " + header);
        String s = System.lineSeparator();
        writer.write("\n" + "System.lineSeparator()" + s);*/

        //查看控制台的输出
        req.getRequestDispatcher("/RequestServlet0").forward(req, resp);
    }
}

